package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.SaleList;
import com.atguigu.jxc.service.SaleListGoodsService;
import com.atguigu.jxc.service.SaleListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author 杨林
 * @create 2023-01-29 23:21 星期日
 * description:
 */
@RestController
@RequestMapping("/saleListGoods")
public class SaleListGoodsController {

    @Autowired
    SaleListService saleListService;

    @Autowired
    SaleListGoodsService saleListGoodsService;

    /**
     * 销售单保存
     * @param saleList
     * @param saleListGoodsStr
     * @return
     */
    @PostMapping("/save")
    public ServiceVO save(SaleList saleList, String saleListGoodsStr){

        return saleListGoodsService.save(saleList,saleListGoodsStr);
    }

    /**
     * 销售单查询（可查询条件：销售单号、客户、付款状态）
     * @param saleNumber
     * @param customerId
     * @param state
     * @param sTime
     * @param eTime
     * @return
     */
    @PostMapping("/list")
    public Map<String,Object> list(String saleNumber,
                                   Integer customerId,
                                   Integer state,
                                   String sTime,
                                   String eTime){

        return saleListService.list(saleNumber,customerId,state,sTime,eTime);
    }


    /**
     * 销售单商品信息
     * @param saleListId
     * @return
     */
    @PostMapping("/goodsList")
    public Map<String,Object> goodsList(Integer saleListId){

        return saleListGoodsService.goodsList(saleListId);
    }


    /**
     * 删除销售单
     * @param saleListId
     * @return
     */
    @PostMapping("/delete")
    public ServiceVO delete(Integer saleListId){

        return saleListService.delete(saleListId);
    }


    /**
     * 支付结算（修改销售单付款状态）
     * @param saleListId
     * @return
     */
    @PostMapping("/updateState")
    public ServiceVO updateState(Integer saleListId){

        return saleListService.updateState(saleListId);
    }


    /**
     * 销售统计（可根据 商品类别、商品编码或名称 条件查询）
     * @param sTime
     * @param eTime
     * @param goodsTypeId
     * @param codeOrName
     * @return
     */
    @PostMapping("/count")
    public String count(String sTime,
                        String eTime ,
                        Integer goodsTypeId,
                        String codeOrName){

        return saleListService.count(sTime,eTime,goodsTypeId,codeOrName);
    }

    /**
     * 按日统计接口
     * @param sTime
     * @param eTime
     * @return
     */
    @PostMapping("/getSaleDataByDay")
    public String getSaleDataByDay(String sTime, String eTime) throws Exception {

        return saleListService.getSaleDataByDay(sTime,eTime);
    }

    /**
     * 按月统计
     * @param sTime
     * @param eTime
     * @return
     */
    @PostMapping("/getSaleDataByMonth")
    public String getSaleDataByMonth(String sTime,
                                     String eTime) throws Exception {

        return saleListService.getSaleDataByMonth(sTime,eTime);
    }
}
